<?
require_once('../../models/Accounts.php');
require_once('../../models/Products.php');
require_once('../../models/Users.php');
require_once ('../../inc/functions.php');

if (!isset($_REQUEST['productType']))
	$productType='all';
else
	$productType=$_REQUEST['productType'];

$response = Products::GetAll();
//session_start();
?>

<!DOCTYPE html>
<html lang="en">
	<?php include('../../inc/head.php'); ?>
	<body>
		<div>
			<?php include('../../inc/nav.php') ?>
		
			<div id="content">
				
				<? if(isLoggedIn()) : ?>
					<? 
					$row=Users::Get($_SESSION['UserId']);
					$first=$row['FirstName'];
					$last=$row['LastName'];
					?>
					Welcome <?=$first?> <?=$last?>
				<? else: ?>
					Log in <a href="../Home/fb_javascript.php">here</a>
				<? endif; ?>
					
			</div>
			
			<div id="content">
				<center><h3>Click item to add to cart</h3></center>
			</div>
			
			<? function RenderInput($itemImage, $itemName, $itemPrice){ ?>
				<? global $row ?>
				<? global $response ?>
				<li> 
					<a href="cart.php?action=add&id=<?=$row['id']?>"> 
						<img src="<?=$itemImage?>"> 
						<h4><?=$itemName?></h4> 
						<p><?=$itemPrice?></p> 
					</a> 
				</li> 
			<? } ?>
			<div id="content">
				<ul class="products">
				<?php 
				while($row = $response->fetch_assoc())
				{
					if ($row['Type']==$productType || $productType=='all')
					{
						//print_r($row);
						RenderInput($row['Image'],$row['Name'],$row['Price']);
					}
				}
				?>
				</ul>
			</div>
			
			
			
			
			
			
			<div id="content">
				<?php include('../../inc/footer.php'); ?>
			</div>
		</div>
	</body>
</html>
